home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / FROMUTS / UNIXLIB37B / src / c / system < prev    next >
Text File  |  1992-03-15  |  1KB  |  63 lines

  1. #ifdef __STDC__
  2. static char sccs_id[] = "@(#) system.c 1.2 "__DATE__" HJR";
  3. #else
  4. static char sccs_id[] = "@(#) system.c 1.2 13/6/91 HJR";
  5. #endif
  6.  
  7. /* system.c (c) Copyright 1990 H.Rogers */
  8.  
  9. #include <stdlib.h>
  10. #include <string.h>
  11.  
  12. #include "sys/param.h"
  13.  
  14. extern int execl(char *,...);
  15. extern int wait(int *);
  16. extern int vfork(void);
  17. extern void _exit(int);
  18.  
  19. #ifdef __STDC__
  20. int system(const char *command)
  21. #else
  22. int system(command)
  23. const char *command;
  24. #endif
  25. {
  26. int w = 0;
  27.  
  28. if (!command) return(-1);
  29.  
  30. switch (vfork())
  31.   {
  32.   case -1:
  33.     return(-1);
  34.     break;
  35.   case 0:
  36.       {
  37.       char *shell,*path;
  38.  
  39. #ifdef ARCH
  40.       if (!(path = getenv("SHELL")))
  41.     {
  42.     if (*command == '*')
  43.       execl((char *)command,0);
  44.     else
  45.       execl("*","",(char *)command,0);
  46.     _exit(1);
  47.     }
  48. #else
  49.       if (!(path = getenv("SHELL"))) path = "/bin/sh";
  50. #endif
  51.       shell = strrchr(path,'/'); if (shell) shell++; else shell = path;
  52.       execl(path,shell,"-c",(char *)command,0);
  53.       _exit(1);
  54.       }
  55.     break;
  56.   default:
  57.     wait(&w);
  58.     break;
  59.   }
  60.  
  61. return(w>>8);
  62. }
  63.